window.TimeoutTool = function(){
    this._wins = {};
    //超时时间
    this.internal = 60*60*1000;// 半个小时;
    //this.internal = 3000;
};

TimeoutTool.prototype = {

    bind : function( context, callback )
    {
        if( callback ) context._callback = callback;

        context._self = this;

        this._wins[ context.name ] = context;

        this.addEventListener( context, "mousemove" , this._event );

        this._event&&this._event.call( context );
    },
    bind2: function(){
        var frmaes = this._wins;

        for(var i in frmaes ){
           if( frmaes[i] )this.addEventListener( frmaes[i], "mousemove" , this._event );
        }
    },

    unbind:function (){

        var frmaes = this._wins;
        for(var i in frmaes ){
           if( frmaes[i] )this.removeEventListener( frmaes[i], "mousemove" , this._event );
        }
    },
    _event : function()
    {
        this._self._clearTimer();

        top.window._timer = setTimeout( this._self._logout , this._self.internal )
    },
    _clearTimer : function(){

        clearTimeout( top.window._timer );
    },

    _logout : function (){

        var _this = this;

        var logout = document.getElementById("ad-js-logoutIn");

        if( logout && logout.style.zIndex != "1000" )
        {
            _this._self.unbind();

            $.get( document.getElementById("exitUserBtn").getAttribute("data-href"), function( data )
            {
                if( data.status )
                {
                    $( logout ).trigger("showModal");
                }

                //toastr.warning( data.info );
            })
        }
    } ,
    addEventListener :function( obj , event , fn ){
        if( obj.addEventListener ){
            obj.addEventListener( event , fn, false )
        }else{
            obj.attachEvent("on"+event,fn);
        }

    },
    removeEventListener : function( obj , event , fn ){
        if( obj.removeEventListener ){
            obj.removeEventListener( event , fn, false )
        }else{
            obj.detachEvent("on"+event,fn);
        }
    }

};